package com.ald.crossex.action.user;

import com.ald.crossex.dto.Principle;
import com.ald.crossex.dto.ResourceRequest;
import com.ald.crossex.dto.ResourceResponse;
import com.ald.crossex.entity.TCeCoreUser;
import com.ald.crossex.service.OrderService;
import com.ald.crossex.service.ResourceService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lishijiong on 15/1/23.
 */
@Controller
@RequestMapping(value = "/admin/resource")
public class ResourceAction {


    @Autowired
    private ResourceService resourceService;

    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * 根据用户id 获取资源
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ResourceResponse getResourceByUserId(HttpServletRequest request) {
        Principle principle = (Principle) request.getSession().getAttribute(Principle.PRINCIPLE_SESSION_ATTRIBUTE_USER);
        TCeCoreUser user = principle.getCeCoreUser();

        ResourceResponse response = new ResourceResponse();
        response.setResources(resourceService.getResourceByUser(user.getUid()));

        return response;
    }



}
